package net.tycmc.cty.ctyms.timejob.iems.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tycmc.functions.util.NumberFormat;

import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;
import net.tycmc.cty.ctyms.timejob.common.ListUtil;
import net.tycmc.cty.ctyms.timejob.iems.dao.VclLoadRemedyStatDAO;

public class VclLoadRemedyStatService {
	
	private VclLoadRemedyStatDAO vclLoadRemedyStatDAO;



	public VclLoadRemedyStatDAO getVclLoadRemedyStatDAO() {
		return vclLoadRemedyStatDAO;
	}

	public void setVclLoadRemedyStatDAO(VclLoadRemedyStatDAO vclLoadRemedyStatDAO) {
		this.vclLoadRemedyStatDAO = vclLoadRemedyStatDAO;
	}
	
	/**
	 * 载重弥补逻辑
	 */
	public void startWork(String HandStatTime) {
		String statTime = "";
		if(StringUtil.isValid(HandStatTime)){
			statTime = HandStatTime;
		} else {
			//统计的数据日期
			 statTime = DateUtil.addDay(-1);
		}
		//String statTime = "2015-09-15";
		System.out.println("载重弥补逻辑统计作业开始,统计的数据日期:"+statTime+"——————————————————————"+DateUtil.toString(new Date()));
		boolean checkSign=true;
		Map<String, Object> mapSign = new HashMap<String, Object>();
		while(checkSign){
			//获取标记，判断平台车天统计表是否统计完成
			mapSign = vclLoadRemedyStatDAO.getStateSign(statTime);
			if(mapSign!=null && mapSign.size()>0){
				if("true".equals(MapGetter.getString(mapSign, "Msg_ESSC_Complete"))){
					checkSign = false;
					System.out.println("载重弥补逻辑统计作业:车天表统计完成，开始统计————————————————————"+DateUtil.toString(new Date()));
				} else {
					System.out.println("载重弥补逻辑统计作业:车天表未统计完成————————————————————"+DateUtil.toString(new Date()));
					try {
						//五分钟后继续下一次扫描
						new Thread().sleep(1000*60*5);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			} else {
				System.out.println("载重弥补逻辑统计作业:车天表未统计完成—————————————————————"+DateUtil.toString(new Date()));
				try {
					//五分钟后继续下一次扫描
					new Thread().sleep(1000*60*5);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		//sql集合
		List<String> sqlListG = new ArrayList<String>();
		//参数集合
		List<Object[]> paramListG = new ArrayList<Object[]>();
		/**---优先将MME载重值更新至合并的字段，再进行弥补逻辑载重的统计更新-----**/
		sqlListG.add(" update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESS_AverageLoad_MidMME = MsgESS_AverageLoad,MsgESS_AverageLoad_ZSMME = MsgESS_AverageLoad ; ");
		paramListG.add(new Object[] {});
		
		sqlListG.add(" update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+statTime.replaceAll("-","").substring(0, 6), "3", null)+" set MsgESS_AverageLoad_MidMME = MsgESS_AverageLoad,MsgESS_AverageLoad_ZSMME = MsgESS_AverageLoad where MsgESS_MsgTime = ? ; ");
		paramListG.add(new Object[] {statTime});
		
		sqlListG.add(" update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_AverageLoad_MidMME = MsgESLS_AverageLoad,MsgESLS_AverageLoad_ZSMME = MsgESLS_AverageLoad,MsgESLS_LoadMidType = MsgESLS_LoadType,MsgESLS_LoadZSType = MsgESLS_LoadType  ; ");
		paramListG.add(new Object[] {});
		
		//批量执行更新
		try {
			 this.vclLoadRemedyStatDAO.insertAllToTable(sqlListG, paramListG);
		} catch (Exception e) {
			System.out.println("-优先将MME载重值更新至合并的字段更新时发生错误！");
		}
		
		//获取需要统计设备的载重统计各时间段
		List<Map<String, Object>> listTimeSecSrc = vclLoadRemedyStatDAO.getLoadTimeSec(statTime);
		if(listTimeSecSrc!=null && listTimeSecSrc.size()>0){
			//sql集合
			List<String> sqlList = new ArrayList<String>();
			//参数集合
			List<Object[]> paramList = new ArrayList<Object[]>();
			//转换LIST为MAP,KEY为设备ID
			Map<String,List<Map<String,Object>>> MapList = new ListUtil().groupBy("MsgESLS_Vcl_ID", listTimeSecSrc);
			//循环，每台设备
			for (Map.Entry<String, List<Map<String, Object>>> entry : MapList.entrySet()) {
				//设备
				String vclid = entry.getKey();
				//String vclid = "154709";
				//每台设备载重区间段
				List<Map<String, Object>> listTimeVclSec = entry.getValue();
				//计算结果--载重值（中数法）
				double midLoadValue = -1;
				//计算结果--载重值（中数法&&MME法）
				double midLoadValueD = -1;
				//计算结果--载重值（众数法）
				double ZSLoadValue = -1;
				//计算结果--载重值（众数法&&MME法）
				double ZSLoadValueD = -1;
				//计算结果--载重值（中数法）每日表用
				double midLoadValueByDay = -1;
				//计算结果--载重值（中数法&&MME法）每日表用
				double midLoadValueDByDay = -1;
				//计算结果--载重值（众数法）每日表用
				double ZSLoadValueByDay = -1;
				//计算结果--载重值（众数法&&MME法）每日表用
				double ZSLoadValueDByDay = -1;
				//时间段开始时间
				String beTime = "";
				//时间段结束时间
				String endTime = "";
				//本条id
				String id = "";
				double oneGearBe = 0;
				double oneGearEd = 0;
				
				int one = 0;
				double twoGearBe = 0;
				double twoGearEd = 0;
				int two = 0;
				double thiGearBe = 0;
				double thiGearEd = 0;
				int thi = 0;
				//后桥速比
				double HQSB = 0;
				//轮胎半径
				double LTBJ = 0;
				//风阻系数(默认为0.6)
				double FZXS = 0.6;
				//迎风面积(默认为9)
				double YFMJ = 9;
				//(中值法的车速偏差默认为3)
				double CSPC = 3;
				//(众数法的车速区间默认为6)
				double CSQJ = 6;
				//(众数法的扭矩区间默认为100)
				double NJQJ = 100;
				//计算所需变速箱速比
				double BSXSB = 0;
				//加权的每日中值法平均载重
				double loadDayMid = 0;
				//加权的工作小时中值法
				double loadHourMid = 0;
				//加权的每日中值法平均载重
				double loadDayZS = 0;
				//加权的工作小时中值法
				double loadHourZS = 0;
				//获取设备状态统计日表平均载重，用于更新
				Map<String, Object> map  = vclLoadRemedyStatDAO.getVclStateLoad(statTime, vclid);
				//获取设备档位及车速设定(最高三档,这里取4档，后面计算用)
				List<Map<String, Object>> listVclGear = vclLoadRemedyStatDAO.getVclGearSet(vclid);
				
				//档位设定为空，直接开始下一条
				if(listVclGear == null || listVclGear.size() == 0 || listVclGear.size() == 1){
					System.out.println("载重弥补逻辑统计作业本条为空,设备id:"+vclid+",统计的数据日期:"+statTime+",档位设定为空或只设定了一档！——————————————"+DateUtil.toString(new Date()));
					continue;
				}
				if(!StringUtil.isValid(MapGetter.getString(listVclGear.get(0), "ParaSD2_TireRadius"))){
					System.out.println("载重弥补逻辑统计作业本条为空,设备id:"+vclid+",统计的数据日期:"+statTime+",档位设定轮胎半径为空！——————————————"+DateUtil.toString(new Date()));
					continue;
				}
				//轮胎半径
				if(!StringUtil.isValid(MapGetter.getString(listVclGear.get(0), "ParaSD2_TireRadius"))){
					System.out.println("载重弥补逻辑统计作业本条为空,设备id:"+vclid+",统计的数据日期:"+statTime+",档位设定轮胎半径为空！——————————————"+DateUtil.toString(new Date()));
					continue;
				} else if(Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSD2_TireRadius")) == 0){
					System.out.println("载重弥补逻辑统计作业本条为空,设备id:"+vclid+",统计的数据日期:"+statTime+",档位设定轮胎半径为0！——————————————"+DateUtil.toString(new Date()));
					continue;
				} else {
					LTBJ = Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSD2_TireRadius"));
				}
				//载重和EBP设定
				Map<String, Object> VclLoadSetMap =  vclLoadRemedyStatDAO.getVclLoadSet(vclid);
				//车速区间
				if(StringUtil.isValid(MapGetter.getString(VclLoadSetMap, "VclLI_ModeSpeedSec"))){
					CSQJ = Double.parseDouble(MapGetter.getString(VclLoadSetMap, "VclLI_ModeSpeedSec"));
				}
				//扭矩区间
				if(StringUtil.isValid(MapGetter.getString(VclLoadSetMap, "VclLI_ModeNJSec"))){
					NJQJ = Double.parseDouble(MapGetter.getString(VclLoadSetMap, "VclLI_ModeNJSec"));
				}
				//载重和EBP设定为空，直接开始下一条
				if(VclLoadSetMap == null || VclLoadSetMap.size() == 0){
					System.out.println("载重弥补逻辑统计作业本条为空,id:"+id+",统计的数据日期:"+statTime+",载重和EBP设定为空！——————————————"+DateUtil.toString(new Date()));
					continue;
				}
				//筛选的车速数据
				List<Map<String, Object>> listSpeedSec  = new ArrayList<Map<String,Object>>();
				List<Map<String, Object>> listSpeedSecOne  = new ArrayList<Map<String,Object>>();
				List<Map<String, Object>> listSpeedSecTwo  = new ArrayList<Map<String,Object>>();
				List<Map<String, Object>> listSpeedSecThi  = new ArrayList<Map<String,Object>>();
				//循环
				for(int i = 0;i<listTimeVclSec.size();i++){
					beTime = MapGetter.getString(listTimeVclSec.get(i), "beTime");
					endTime = MapGetter.getString(listTimeVclSec.get(i), "endTime");
					id = MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_ID");
					//获取时间段内车辆的变速箱速比、车速、发动机扭矩三个PP参数
					List<Map<String, Object>> listParamSec = vclLoadRemedyStatDAO.getPPParamSec(statTime, beTime, endTime,vclid);
					//PP参数获取为空，直接开始下一条
					if(listParamSec == null || listParamSec.size() == 0){
						System.out.println("载重弥补逻辑统计作业本条为空,id:"+id+",统计的数据日期:"+statTime+",PP参数获取为空！——————————————"+DateUtil.toString(new Date()));
						continue;
					}
					//根据变速箱速比筛选数据
					for(int j = 0;j<listParamSec.size();j++){
						double gearRation = 0;
						//本条变速箱速比（为空的速比不比较）
						if(StringUtil.isValid(MapGetter.getString(listParamSec.get(j), "MsgUC_UDSValueB"))){
							gearRation = Double.parseDouble(MapGetter.getString(listParamSec.get(j), "MsgUC_UDSValueB"));
						} else {
							continue;
						}
						//配置了2个档位，计算最高一档所属范围值
						if(listVclGear.size() == 2){
							oneGearBe = 0;
							oneGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio"))), 2,2);
							//将本条变速箱速比，与档位范围比较，在所属范围记录本档位一次，并记录本条数据
							if(gearRation>=oneGearBe && gearRation<oneGearEd){
								one++;
								listSpeedSecOne.add(listParamSec.get(j));
							}
						}
						//配置了3个档位，计算最高一档、二档所属范围值
						if(listVclGear.size() == 3){
							oneGearBe = 0;
							oneGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio"))), 2,2);
							
							twoGearBe = oneGearEd;
							twoGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(2), "ParaSDD2_DriRatio"))), 2,2);
							//将本条变速箱速比，与档位范围比较，在所属范围记录本档位一次，并记录本条数据
							if(gearRation>=oneGearBe && gearRation<oneGearEd){
								one++;
								listSpeedSecOne.add(listParamSec.get(j));
							}
							
							if(gearRation>=twoGearBe && gearRation<twoGearEd){
								two++;
								listSpeedSecTwo.add(listParamSec.get(j));
							}
							
						}
						//配置够4个档位，计算最高一档、二档、三档所属范围值
						if(listVclGear.size() == 4){
							oneGearBe = 0;
							oneGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio"))), 2,2);
							
							twoGearBe = oneGearEd;
							twoGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(2), "ParaSDD2_DriRatio"))), 2,2);
							
							thiGearBe = twoGearEd;
							thiGearEd = NumberFormat.div(NumberFormat.add(Double.parseDouble(MapGetter.getString(listVclGear.get(2), "ParaSDD2_DriRatio")), Double.parseDouble(MapGetter.getString(listVclGear.get(3), "ParaSDD2_DriRatio"))), 2,2);
						
							//将本条变速箱速比，与档位范围比较，在所属范围记录本档位一次，并记录本条数据
							if(gearRation>=oneGearBe && gearRation<oneGearEd){
								one++;
								listSpeedSecOne.add(listParamSec.get(j));
							}
							
							if(gearRation>=twoGearBe && gearRation<twoGearEd){
								two++;
								listSpeedSecTwo.add(listParamSec.get(j));
							}
							
							if(gearRation>=thiGearBe && gearRation<thiGearEd){
								thi++;
								listSpeedSecThi.add(listParamSec.get(j));
							}
						}
						
					//筛选数据
					//只配置2档位
					if(listVclGear.size() == 2){
						listSpeedSec = listSpeedSecOne;
						BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio"));
					}
					//配置3个档位
					if(listVclGear.size() == 3){
						if(one>=two){
							listSpeedSec = listSpeedSecOne;
							BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio"));
						}
						if(one<two){
							listSpeedSec = listSpeedSecTwo;
							BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio"));
						}
					}
					//配置够4个档位
					if(listVclGear.size() == 4){
						if(one>=two){
							if(one>=thi){
								listSpeedSec = listSpeedSecOne;
								BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSDD2_DriRatio"));
							}
							if(one<thi){
								listSpeedSec = listSpeedSecThi;
								BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(2), "ParaSDD2_DriRatio"));
							}
						}
						if(one<two){
							if(two>=thi){
								listSpeedSec = listSpeedSecTwo;
								BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(1), "ParaSDD2_DriRatio"));
							}
							if(two<thi){
								listSpeedSec = listSpeedSecThi;
								BSXSB = Double.parseDouble(MapGetter.getString(listVclGear.get(2), "ParaSDD2_DriRatio"));
							}
						}
					}
				}
					//根据筛选出的车速值，算出中位数
					if(listSpeedSec == null || listSpeedSec.size() == 0){
						System.out.println("载重弥补逻辑统计作业,筛选的车速List值为空,id:"+id+",统计的数据日期:"+statTime+"！——————————————"+DateUtil.toString(new Date()));
						continue;
					}
					//过滤掉速度小于等于0的值
					//list排序用
					List<Map<String,Object>> dateList = new ArrayList<Map<String,Object>>();
					//区间集合
					Map<Double,Double[]> mapCSQJ = new HashMap<Double, Double[]>();
					for(Map<String,Object> mm : listSpeedSec){
						if(StringUtil.isValid(MapGetter.getString(mm, "MsgUC_UDSValueC"))){
							if(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC"))>0){
								//区间
								Double[] ZSSPArea = new Double[2];
								dateList.add(mm);
								//将车速值取整
								ZSSPArea[0] = (double) Math.round(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC")));
								ZSSPArea[1] =  Math.round(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC")))+CSQJ;
								mapCSQJ.put(ZSSPArea[0], ZSSPArea);
							}
						}
					}
			/**------------------------------------------------------------------------中值法和众数法公用-----------END-----------------------------------------------------------------------**/					
					if(dateList==null || dateList.size()==0){
						continue;
					}
			/**------------------------------------------------------------------------中值法算出计算所需速度和扭矩---Start----------------------------------------------------------------------**/		
					//车速中位数
					double midNumC = getMidNum(dateList,"MsgUC_UDSValueC");
					if(midNumC == -1){
						System.out.println("载重弥补逻辑统计作业,筛选的车速大于等于0值的List为空,id:"+id+",统计的数据日期:"+statTime+"！——————————————"+DateUtil.toString(new Date()));
					}
					//过滤掉扭矩值小于等于0,且不在中值法的车速偏差的值
					//list排序用
					List<Map<String,Object>> dateListF = new ArrayList<Map<String,Object>>();
					//车速偏差
					if(StringUtil.isValid(MapGetter.getString(VclLoadSetMap, "VclLI_MidSpeedDev"))){
						CSPC = Double.parseDouble(MapGetter.getString(VclLoadSetMap, "VclLI_MidSpeedDev"));
					}
					for(Map<String,Object> mm : dateList){
						if(StringUtil.isValid(MapGetter.getString(mm, "MsgUC_UDSValueC"))){
							if(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC"))>0 && Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueF"))>0){
								if(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC"))<=midNumC+CSPC && Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueC"))>=midNumC-CSPC){
									dateListF.add(mm);
								}
							}
						}
					}
					//扭矩中位数
					double midNumF = getMidNum(dateListF,"MsgUC_UDSValueF");
					if(midNumF == -1){
						System.out.println("载重弥补逻辑统计作业,筛选的扭矩值大于等于0值的List为空,id:"+id+",统计的数据日期:"+statTime+"！——————————————"+DateUtil.toString(new Date()));
					}
			/**------------------------------------------------------------------------中值法算出所需速度和扭矩--------END----------------------------------------------------------------------**/	
			/**------------------------------------------------------------------------众数法算出计算所需速度和扭矩---Start----------------------------------------------------------------------**/		
					Map<String,List<Map<String,Object>>>  MapSpZs = new HashMap<String, List<Map<String,Object>>>();
					//筛选区间数据最多用
					List<String> listSP = new ArrayList<String>();
					//循环车速区间
					for (Map.Entry<Double, Double[]> entryZSSP : mapCSQJ.entrySet()) {
						Double key = entryZSSP.getKey();
						//区间
						Double[] value = entryZSSP.getValue();
						//区间对应筛选的LIST
						List<Map<String,Object>> listCSZs = new ArrayList<Map<String,Object>>();
						for(int m = 0;m<dateList.size();m++){
							if(Double.parseDouble(MapGetter.getString(dateList.get(m), "MsgUC_UDSValueC"))>=value[0] &&
									Double.parseDouble(MapGetter.getString(dateList.get(m), "MsgUC_UDSValueC"))<=value[1]){
								listCSZs.add(dateList.get(m));
							}
						
						}
						if(listCSZs!=null && listCSZs.size()>0){
							//key:区间开始车速值~对应区间列表大小  value：区间列表
							MapSpZs.put(key+"~"+listCSZs.size(), listCSZs);
							listSP.add(key+"~"+listCSZs.size());
						}
					}
					//车速分布区间最多list
					List<Map<String,Object>> listZSSpd = new ArrayList<Map<String,Object>>();
					//对LIST排序，筛选出区间最多的listCSZs
					if(listSP!=null && listSP.size()>0){
						String as = "";
						//先按KEY值中的区间开始值排序
						for(int z = 0; z < listSP.size() - 1; z++) {
							for(int x = 1;x<listSP.size()-z;x++){
								Double c = Double.parseDouble(listSP.get(x-1).split("~")[0]);
								Double d = Double.parseDouble(listSP.get(x).split("~")[0]);
								if (c>d) {
									//从低至高排序
									as = listSP.get(x - 1);   
									listSP.set((x-1), listSP.get(x));
									listSP.set(x, as);   
								}
							}
						}
						//按KEY值中的车速值排序
						for(int z = 0; z < listSP.size() - 1; z++) {
							for(int x = 1;x<listSP.size()-z;x++){
								Double a = Double.parseDouble(listSP.get(x-1).split("~")[1]);
								Double b = Double.parseDouble(listSP.get(x).split("~")[1]);
								if (a>=b) {
									//从低至高排序
									as = listSP.get(x - 1);   
									listSP.set((x-1), listSP.get(x));
									listSP.set(x, as);   
								}
							}
						}
						listZSSpd = MapSpZs.get(listSP.get(listSP.size()-1));
					}
					//车速中位数
					double ZSNumC = getMidNum(listZSSpd,"MsgUC_UDSValueC");
					if(ZSNumC == -1){
						System.out.println("载重弥补逻辑统计作业,众数筛选的车速大于等于0值的List为空,id:"+id+",统计的数据日期:"+statTime+"！——————————————"+DateUtil.toString(new Date()));
					}
					
					//过滤掉扭矩小于等于0的值
					//list排序用
					List<Map<String,Object>> ZSdateListF = new ArrayList<Map<String,Object>>();
					//区间集合
					Map<Double,Double[]> mapNJQJ = new HashMap<Double, Double[]>();
					if(listZSSpd!=null && listZSSpd.size()>0){
						for(Map<String,Object> mm : listZSSpd){
							if(StringUtil.isValid(MapGetter.getString(mm, "MsgUC_UDSValueF"))){
								if(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueF"))>0){
									//区间
									Double[] ZSNJArea = new Double[2];
									ZSdateListF.add(mm);
									//将扭矩值取整
									ZSNJArea[0] = (double) Math.round(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueF")));
									ZSNJArea[1] =  Math.round(Double.parseDouble(MapGetter.getString(mm, "MsgUC_UDSValueF")))+NJQJ;
									mapNJQJ.put(ZSNJArea[0], ZSNJArea);
								}
							}
						}
					}
					//扭矩分布区间最多list
					List<Map<String,Object>> listZSNJd = new ArrayList<Map<String,Object>>();
					if(ZSdateListF!=null && ZSdateListF.size()>0){
						Map<String,List<Map<String,Object>>>  MapNjZs = new HashMap<String, List<Map<String,Object>>>();
						//筛选区间数据最多用
						List<String> listNJ = new ArrayList<String>();
						//循环车速区间
						for (Map.Entry<Double, Double[]> entryZSNJ : mapNJQJ.entrySet()) {
							Double key = entryZSNJ.getKey();
							//区间
							Double[] value = entryZSNJ.getValue();
							//区间对应筛选的LIST
							List<Map<String,Object>> listCSZs = new ArrayList<Map<String,Object>>();
							for(int m = 0;m<ZSdateListF.size();m++){
								if(Double.parseDouble(MapGetter.getString(ZSdateListF.get(m), "MsgUC_UDSValueF"))>=value[0] &&
										Double.parseDouble(MapGetter.getString(ZSdateListF.get(m), "MsgUC_UDSValueF"))<=value[1]){
										listCSZs.add(ZSdateListF.get(m));
								}
						
							}
							if(listCSZs!=null && listCSZs.size()>0){
								//key:区间开始时间~对应区间列表大小  value：区间列表
								MapNjZs.put(key+"~"+listCSZs.size(), listCSZs);
								listNJ.add(key+"~"+listCSZs.size());
							}
						}
						//对LIST排序，筛选出区间最多的listCSZs
						if(listNJ!=null && listNJ.size()>0){
							String as = "";
							for(int z = 0; z < listNJ.size() - 1; z++) {
								for(int x = 1;x<listNJ.size()-z;x++){
									Double c = Double.parseDouble(listNJ.get(x-1).split("~")[0]);
									Double d = Double.parseDouble(listNJ.get(x).split("~")[0]);
									if (c>d) {
										//从低至高排序
										as = listNJ.get(x - 1);   
										listNJ.set((x-1), listNJ.get(x));
										listNJ.set(x, as);   
									}
								}
							}
							for(int z = 0; z < listNJ.size() - 1; z++) {
								for(int x = 1;x<listNJ.size()-z;x++){
									Double a = Double.parseDouble(listNJ.get(x-1).split("~")[1]);
									Double b = Double.parseDouble(listNJ.get(x).split("~")[1]);
									if (a>=b) {
										//从低至高排序
										as = listNJ.get(x - 1);   
										listNJ.set((x-1), listNJ.get(x));
										listNJ.set(x, as);   
									}
								}
							}
							listZSNJd = MapNjZs.get(listNJ.get(listNJ.size()-1));
						}
					}
					//扭矩中位数
					double ZSNumF = getMidNum(listZSNJd,"MsgUC_UDSValueF");
					if(ZSNumF == -1){
						System.out.println("载重弥补逻辑统计作业,众数筛选的扭矩大于等于0值的List为空,id:"+id+",统计的数据日期:"+statTime+"！——————————————"+DateUtil.toString(new Date()));
					}
			/**------------------------------------------------------------------------众数法算出所需速度和扭矩---END--------------------------------------------------------------------------**/	
					/**----------------计算载重-------------------------------------------------**/
					//后桥速比
					if(StringUtil.isValid(MapGetter.getString(listVclGear.get(0), "ParaSD2_RearAxleRatio"))){
						HQSB = Double.parseDouble(MapGetter.getString(listVclGear.get(0), "ParaSD2_RearAxleRatio"));
					}
					//风阻系数
					if(StringUtil.isValid(MapGetter.getString(VclLoadSetMap, "VclLI_WindStopCoe"))){
						FZXS = Double.parseDouble(MapGetter.getString(VclLoadSetMap, "VclLI_WindStopCoe"));
					}
					//迎风面积
					if(StringUtil.isValid(MapGetter.getString(VclLoadSetMap, "VclLI_MeetWindArea"))){
						YFMJ = Double.parseDouble(MapGetter.getString(VclLoadSetMap, "VclLI_MeetWindArea"));
					}
					if(midNumC != -1 && midNumF != -1){
						midLoadValue = NumberFormat.div(
								midNumF*HQSB*BSXSB/(LTBJ/1000)-(FZXS*YFMJ*midNumC*midNumC/
										21.15)
										,(0.0076+0.000056*midNumC)*9800);
						//载重值根据配置进行调整
						midLoadValue = adjustLoad(midLoadValue,VclLoadSetMap);
					}
					if(ZSNumC != -1 && ZSNumF != -1){
						ZSLoadValue = NumberFormat.div(
								ZSNumF*HQSB*BSXSB/(LTBJ/1000)-(FZXS*YFMJ*ZSNumC*ZSNumC/
										21.15)
										,(0.0076+0.000056*ZSNumC)*9800);
						//载重值根据配置进行调整
						ZSLoadValue = adjustLoad(ZSLoadValue,VclLoadSetMap);
					}
					
					if(StringUtil.isValid(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_AverageLoad"))){
						if(-1!=Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_AverageLoad"))){
							midLoadValueD = Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_AverageLoad"));
							ZSLoadValueD = Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_AverageLoad"));
						} else {
							midLoadValueD = midLoadValue;
							ZSLoadValueD = ZSLoadValue;
						}
					}else {
						midLoadValueD = midLoadValue;
						ZSLoadValueD = ZSLoadValue;
					}
					//更新载重统计每日表
					sqlList.add(" update  "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_AverageLoad_Mid = ?,MsgESLS_AverageLoad_MidMME = ?,MsgESLS_AverageLoad_ZS = ?,MsgESLS_AverageLoad_ZSMME = ? where MsgESLS_ID = ?; ");
					paramList.add(new Object[] {midLoadValue,midLoadValueD,ZSLoadValue,ZSLoadValueD,id});
					//更新载重类型中值法
					adjustLoadType(midLoadValueD,VclLoadSetMap,sqlList,paramList,id,statTime,1);
					
					//更新载重类型众数法
					adjustLoadType(ZSLoadValueD,VclLoadSetMap,sqlList,paramList,id,statTime,2);
					
					//将同设备的区间载重进行加权
					if(StringUtil.isValid(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_IntervalWorkTime"))){
						loadDayMid = NumberFormat.add(loadDayMid, midLoadValue*Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_IntervalWorkTime")));
						loadHourMid = NumberFormat.add(loadHourMid, Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_IntervalWorkTime")));
						loadDayZS = NumberFormat.add(loadDayZS, ZSLoadValue*Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_IntervalWorkTime")));
						loadHourZS = NumberFormat.add(loadHourZS, Double.parseDouble(MapGetter.getString(listTimeVclSec.get(i), "MsgESLS_IntervalWorkTime")));
					}
				
			}
				//设备状态统计每日表载重
				if(loadHourMid>0){
					midLoadValueByDay = NumberFormat.div(loadDayMid, loadHourMid, 2);
				}
				//设备状态统计每日表载重
				if(loadHourZS>0){
					ZSLoadValueByDay = NumberFormat.div(loadDayZS, loadHourZS, 2);
				}
				if(map!=null && map.size()>0){
					if(StringUtil.isValid(MapGetter.getString(map, "MsgESS_AverageLoad"))){
						if(-1!=Double.parseDouble(MapGetter.getString(map, "MsgESS_AverageLoad"))){
							midLoadValueDByDay = Double.parseDouble(MapGetter.getString(map, "MsgESS_AverageLoad"));
							ZSLoadValueDByDay = Double.parseDouble(MapGetter.getString(map, "MsgESS_AverageLoad"));
						} else {
							midLoadValueDByDay = midLoadValueByDay;
							ZSLoadValueDByDay = ZSLoadValueByDay;
						}
					} else {
						midLoadValueDByDay = midLoadValueByDay;
						ZSLoadValueDByDay = ZSLoadValueByDay;
					}
				}
				//更新设备状态统计每日表
				sqlList.add(" update  "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESS_AverageLoad_Mid = ?,MsgESS_AverageLoad_MidMME = ?,MsgESS_AverageLoad_ZS = ?,MsgESS_AverageLoad_ZSMME = ? where MsgESS_Vcl_ID = ?; ");
				paramList.add(new Object[] {midLoadValueByDay,midLoadValueDByDay,ZSLoadValueByDay,ZSLoadValueDByDay,vclid});
				
				//更新设备状态统计月表
				sqlList.add(" update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_Statistics_"+statTime.replaceAll("-","").substring(0, 6), "3", null)+" set MsgESS_AverageLoad_Mid = ?,MsgESS_AverageLoad_MidMME = ?,MsgESS_AverageLoad_ZS = ?,MsgESS_AverageLoad_ZSMME = ? where MsgESS_Vcl_ID = ? and MsgESS_MsgTime = ?; ");
				paramList.add(new Object[] {midLoadValueByDay,midLoadValueDByDay,ZSLoadValueByDay,ZSLoadValueDByDay,vclid,statTime});
		} 
			//批量执行更新
			try {
				 this.vclLoadRemedyStatDAO.insertAllToTable(sqlList, paramList);
			} catch (Exception e) {
				System.out.println("载重弥补逻辑批量数据插入时发生错误！");
			}
		}else {
			System.out.println("载重弥补逻辑统计作业结束,统计的数据日期:"+statTime+",载重统计各时间段源数据为空！——————————————"+DateUtil.toString(new Date()));
		}
		//统计结束，更新车天统计标记表
		try {
			 this.vclLoadRemedyStatDAO.setStateSign(statTime);
		} catch (Exception e) {
			System.out.println("载重弥补逻辑更新车天统计标记表时发生错误！");
		}
		System.out.println("载重弥补逻辑统计作业结束,统计的数据日期:"+statTime+"——————————————"+DateUtil.toString(new Date()));
		
	}
	
	/**
	 * 求中数
	 * @param listdata
	 * @return
	 */
	public double getMidNum(List<Map<String, Object>> dateList,String key){
		double oneNum = 0;
		double twoNum = 0;
		double Num = 0;
		//对有数据的dateList进行排序
		Map<String,Object> temp  = new HashMap<String, Object>();
		if(dateList!=null && dateList.size()>0){
			for(int i = 0; i < dateList.size() - 1; i++) {
				for(int j = 1;j<dateList.size()-i;j++){
					Double a = Double.parseDouble((MapGetter.getString(dateList.get(j-1),key)));
					Double b = Double.parseDouble((MapGetter.getString(dateList.get(j),key)));
					if (a.compareTo(b)>0) {
						//从低至高排序
						temp = dateList.get(j - 1);   
						dateList.set((j-1), dateList.get(j));
						dateList.set(j, temp);   
					}
				
				}
			}
			//偶数个
			if(dateList.size()%2 == 0){
				oneNum = Double.parseDouble(MapGetter.getString(dateList.get(dateList.size()/2-1),key));
				twoNum = Double.parseDouble(MapGetter.getString(dateList.get(dateList.size()/2),key));
				Num = NumberFormat.div(NumberFormat.add(oneNum, twoNum), 2, 2);
				//单数个
			} else {
				oneNum = Double.parseDouble(MapGetter.getString(dateList.get(dateList.size()/2),key));
				Num = NumberFormat.div(oneNum, 1, 2);
			}
			return Num;
		} else {
			return -1;
		}
		
	}
	
	/**
	 * 弥补后，载重类型调整
	 * @param loadValue
	 * @param loadSet
	 * @return
	 */
	public void adjustLoadType(double loadValue,Map<String,Object> loadSet,List<String> sqlList,List<Object[]> paramList,String id,String statTime,int type){
		
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnNoLoad")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndNoLoad"))){
			double VclLI_BgnNoLoad = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnNoLoad"));
			double VclLI_EndNoLoad =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndNoLoad"));
			if(loadValue*1000>VclLI_BgnNoLoad&&loadValue*1000<=VclLI_EndNoLoad){//空载
				if(type == 1){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadMidType = 1 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
				if(type == 2){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadZSType = 1 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnLoad")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndLoad"))){
			double VclLI_BgnLoad = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnLoad"));
			double VclLI_EndLoad =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndLoad"));
			if(loadValue*1000>VclLI_BgnLoad&&loadValue*1000<=VclLI_EndLoad){//装载
				if(type == 1){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadMidType = 2 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
				if(type == 2){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadZSType = 2 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnFullLoad")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndFullLoad"))){
			double VclLI_BgnFullLoad = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnFullLoad"));
			double VclLI_EndFullLoad =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndFullLoad"));
			if(loadValue*1000>VclLI_BgnFullLoad&&loadValue*1000<=VclLI_EndFullLoad){//满载
				if(type == 1){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadMidType = 3 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
				if(type == 2){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadZSType = 3 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnSpeFullLoad")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndSpeFullLoad"))){
			double VclLI_BgnSpeFullLoad = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnSpeFullLoad"));
			double VclLI_EndSpeFullLoad =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndSpeFullLoad"));
			if(loadValue*1000>VclLI_BgnSpeFullLoad&&loadValue*1000<=VclLI_EndSpeFullLoad){//特满载
				if(type == 1){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadMidType = 4 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
				if(type == 2){
					sqlList.add("update "+GlobalDBVar.getDBFullName_Conn("Msg_EquipmentState_LoadStatistics_"+statTime.replaceAll("-",""), "3", null)+" set MsgESLS_LoadZSType = 4 where MsgESLS_ID = ?;");
					paramList.add(new Object[] {id});
				}
			}
			
		}
	}
	/**
	 * 载重值调整
	 * @param loadValue
	 * @param loadSet
	 * @return
	 */
	public double adjustLoad(double loadValue,Map<String,Object> loadSet){
		
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnOne")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndOne"))
				&& StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_OneRegM")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_OneRegR"))){
			double VclLI_BgnOne = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnOne"));
			double VclLI_EndOne =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndOne"));
			double VclLI_OneRegM =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_OneRegM")); 
			double VclLI_OneRegR = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_OneRegR"));
			if(loadValue>=VclLI_BgnOne&&loadValue<=VclLI_EndOne){//第一段
				loadValue = loadValue*VclLI_OneRegM+VclLI_OneRegR;
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnTwo")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndTwo"))
				&& StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_TwoRegM")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_TwoRegR"))){
			double VclLI_BgnTwo = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnTwo"));
			double VclLI_EndTwo =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndTwo"));
			double VclLI_TwoRegM =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_TwoRegM")); 
			double VclLI_TwoRegR = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_TwoRegR"));
			if(loadValue>=VclLI_BgnTwo&&loadValue<=VclLI_EndTwo){//第二段
				loadValue = loadValue*VclLI_TwoRegM+VclLI_TwoRegR;
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnThree")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndThree"))
				&& StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_ThreeRegM")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_ThreeRegR"))){
			double VclLI_BgnThree = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnThree"));
			double VclLI_EndThree =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndThree"));
			double VclLI_ThreeRegM =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_ThreeRegM")); 
			double VclLI_ThreeRegR = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_ThreeRegR"));
			if(loadValue>=VclLI_BgnThree&&loadValue<=VclLI_EndThree){//第三段
				loadValue = loadValue*VclLI_ThreeRegM+VclLI_ThreeRegR;
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnFour")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndFour"))
				&& StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_FourRegM")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_FourRegR"))){
			double VclLI_BgnFour = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnFour"));
			double VclLI_EndFour =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndFour"));
			double VclLI_FourRegM =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_FourRegM")); 
			double VclLI_FourRegR = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_FourRegR"));
			if(loadValue>=VclLI_BgnFour&&loadValue<=VclLI_EndFour){//第四段
				loadValue = loadValue*VclLI_FourRegM+VclLI_FourRegR;
			}
			
		}
		if(StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_BgnFive")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_EndFive"))
				&& StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_FiveRegM")) && StringUtil.isValid(MapGetter.getString(loadSet, "VclLI_FiveRegR"))){
			double VclLI_BgnFive = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_BgnFive"));
			double VclLI_EndFive =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_EndFive"));
			double VclLI_FiveRegM =  Double.parseDouble(MapGetter.getString(loadSet, "VclLI_FiveRegM")); 
			double VclLI_FiveRegR = Double.parseDouble(MapGetter.getString(loadSet, "VclLI_FiveRegR"));
			if(loadValue>=VclLI_BgnFive&&loadValue<=VclLI_EndFive){//第五段
				loadValue = loadValue*VclLI_FiveRegM+VclLI_FiveRegR;
			}
			
		}
		return loadValue;
		
	}
	
	public static void main(String[] args) {
		
		for(int i = 0;i<4;i++){
			//车速取整
			//车速区间开始   //车速区间结束
			try {
				new Thread().sleep(6000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(DateUtil.addDay(-i));
		}
		for(int i = 4;i<6;i++){
	
		}
		System.out.println(Math.round(2.6));
		List<String> listSP = new ArrayList<String>();
		listSP.add("3~20");
		listSP.add("4~40");
		listSP.add("5~40");
		listSP.add("6~20");
		listSP.add("7~10");
		listSP.add("9~40");
		String as = "";
		for(int z = 0; z < listSP.size() - 1; z++) {
			for(int x = 1;x<listSP.size()-z;x++){
				Double a = Double.parseDouble(listSP.get(x-1).split("~")[1]);
				Double b = Double.parseDouble(listSP.get(x).split("~")[1]);
				Double c = Double.parseDouble(listSP.get(x-1).split("~")[0]);
				Double d = Double.parseDouble(listSP.get(x).split("~")[0]);
				if (a>=b) {
		
						//从低至高排序
						as = listSP.get(x - 1);   
						listSP.set((x-1), listSP.get(x));
						listSP.set(x, as);
					
				}
			}
		}
		System.out.println(Double.parseDouble("350.23")+Double.parseDouble("0.0026542"));
			String statTime = DateUtil.addDay(-13);
			System.out.println(statTime);
			System.out.println(statTime.replaceAll("-", "").substring(0, 6));
		System.out.println(DateRegUtil.getDaysOfTimeDef(new String[]{"2015-01-10","2015-01-05"}));
		System.out.println(Double.parseDouble(String.valueOf(2))/Double.parseDouble(String.valueOf(5)));
	}
}
